<script setup>
import {storeToRefs} from 'pinia'
import {user} from '@/stores/counter.js'
import {HomeFilled} from "@element-plus/icons-vue";

const userStore = user()
const {userName} = storeToRefs(userStore)

</script>

<template>

  <el-affix :offset="0">
    <div class="navbar">
      <div class="link-menu">

        <span v-if="userName == null">
          <button class="link-button" @click="item => {this.$router.push('/login')}">
          你好，
          <span style="color: #E2231A">请登录</span>
        </button>
        </span>

        <span v-if="userName != null">
          <button class="link-button" @click="item => {this.$router.push('/login')}">
          欢迎您，
          <span style="color: #E2231A">{{ userName }}</span>
        </button>
        </span>

        <el-divider direction="vertical" style="background-color: #A0A0A0"/>
        <button class="link-button" @click="item => {this.$router.push('/login')}">微博广场</button>
        <el-divider direction="vertical" style="background-color: #A0A0A0"/>
        <button class="link-button" @click="item => {this.$router.push('/cart')}">我的评论</button>
        <el-divider direction="vertical" style="background-color: #A0A0A0"/>
        <button class="link-button" @click="item => {this.$router.push('/history')}">我的关注</button>
      </div>
    </div>
  </el-affix>
</template>

<style scoped>

.navbar {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  background-color: #E3E4E5;
  padding: 5px 30px 5px 30px;
}

.link-menu {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
}

.link-button {
  border: none;
  background-color: transparent;
  color: #A0A0A0;
  transition: color 0.3s;
}

.link-button:hover {
  color: #F00619;
}
</style>